const config = require('../../config.js');
const utils = require('../../utils/util.js');
const request = require('../../utils/request.js')
import { getStoreData, indexOrderCount } from '../../static/api/api.js'
//获取应用实例
var app = getApp()
Page({
    data: {
        curOrderData:null,
        curDataIndex:0,
        memberData:null,
        isShowNewCoupon: false,
        storeData:null

    },
    onShow:function(){
        let that = this;
        that.getStoreData()
        
    },
    onLoad: function(options) {
        let that = this;
        this.setData({
            'memberData': app.globalData.memberInfo
        })
        wx.hideShareMenu({

        })
        
    },
    onPageScroll: function(res) {

    },
    onShareAppMessage: function () {
        return {}
    },
    onPullDownRefresh: function() {
        let that = this;
        this.getStoreData()
        
    },
    //获取用户数据
    getStoreData(){
        let that = this;
        console.log('开始触发事件')
        getStoreData().then(response => {
            console.log(response)
            that.setData({
                'storeData': response.data,
                'curOrderData': response.data.count_order
            })
            wx.stopPullDownRefresh()
        }).catch(response => {

        })
        
    },
    changeOrderStatus(e){
        let that = this;
        let dataset = e.currentTarget.dataset;
        this.setData({
            curDataIndex: dataset.type
        })
        wx.showLoading({
            title: '加载中...',
        })
        indexOrderCount({ 'date_type': this.data.curDataIndex}).then(response => {
            wx.hideLoading();
            console.log(response)
            that.setData({
                'curOrderData': response.data
            })
        }).catch(response => {
            wx.hideLoading();
        })
    },
    goUrl(e){
        utils.goNavigationUrl(e)
    },
    goWriteOff(){
        wx.switchTab({
            url: '/pages/write_off_cart/write_off_cart',
        })
    }
})